package com.le.tester.book.effectivejava3rdchinese.secondReading.l34;

/**
 * createTime：2024-09-13 14:14
 * description：支付类型,灵活到可以计算每天需要的工资，而且仅需在enum中增加类型
 * 还是把公共的方法进行更好的封装，可以让调用方根据自己的需求根据需要来进行参数的传递
 * 还有就是一个枚举类型中的常量集不需要一直保持不变
 */
enum PayrollDay {
    MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY,
    SATURDAY(PayType.WEEKEND), SUNDAY(PayType.WEEKEND);

    private final PayType payType;

    PayrollDay(PayType payType) {
        this.payType = payType;
    }

    PayrollDay() {
        this(PayType.WEEKDAY);
    }

    int pay(int minsWorked, int payRate) {
        return payType.pay(minsWorked, payRate);
    }


}

public enum PayType {

    WEEKDAY {
        int overtimePay(int minsWorked, int payRate) {
            return minsWorked <= MINS_PER_SHIFT ? 0 : (minsWorked - MINS_PER_SHIFT) * payRate / 2;
        }
    },
    WEEKEND {
        int overtimePay(int minsWorked, int payRate) {
            return minsWorked * payRate / 2;

        }
    };



    //调用方可以直接调用
    abstract int overtimePay(int mins, int payRate);

    private static final int MINS_PER_SHIFT = 8 * 60;

    int pay(int minsWorked, int payRate) {
        int basePay = minsWorked * payRate;
        return basePay + overtimePay(minsWorked, payRate);
    }
}
